<?php
@session_start();

require_once '../../config/config.inc';


$errmsg=array();
$errflag=false;
$conn = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
if(!$conn){
	echo mysql_error();
}
$db=mysql_select_db(DB_DATABASE);
if(!$db){
	mysql_error();
}
function clean($str){
	if(get_magic_quotes_gpc()){
		$str=stripcslashes($str);
	}

	return mysql_real_escape_string($str);
}
if(isset($_POST['submit'])) {
	$title=clean($_POST['title']);
	$sdate=clean($_POST['sdate']);
	$edate=clean($_POST['edate']);
	$select=clean($_POST['select']);
	$venue=clean($_POST['venue']);
	$description=clean($_POST['textarea']);
	$photo=$_FILES['photo']['name'];
	$agenda=$_FILES['file']['name'];
	$speakar=clean($_POST['speakar']);
	$partnar=clean($_POST['partnar']);
	$sponsor=clean($_POST['sponsor']);
	$organizer=clean($_POST['organizer']);
	$exihabitevent=clean($_POST['exhibition']);
	$sponsorevent=clean($_POST['sponsor']);
	$id=$_POST['id'];
	$query=mysql_query("select * from `event` where id='$id'");
	$uprow=mysql_fetch_array($query);
     $updateag=$uprow['agenda'];
     $uploadfile="../../assets/uploadfile/";
	$uploadfile=$uploadfile.basename($_FILES['file']['name']);
	$ok=1;
	if(move_uploaded_file($_FILES['file']['tmp_name'],$uploadfile)){
		echo "file has been uploaded".basename($_FILES['file']['name']);
	}else{
		echo mysql_error()."file has been not uploaded try agine";
		
	}
	
	
	$txt;$ext;
	mysql_query("SET NAMES UTF8");
	mysql_query("SET CHARACHAR_SET UTF8");
	$path="../../assets/img/eventphoto/";
	$validformat=array("jpg","png","gif","bmp","JPG","PNG","GIF","BMP");
	$name=$_FILES['photo']['name'];
	$size=$_FILES['photo']['size'];
	if($name==""||$name==null){
	$update=mysql_query("UPDATE `event` SET `title`='$title',`startdate`='$sdate',`enddate`='$edate',
  `venue`='$venue',`description`='$description',`agenda`='$agenda',
`speaker`='$speakar',`partner`='$partnar',`sponsor`='$sponsor',`organizer`='$organizer',
 `doyou_want_exihabit`='$exihabitevent',`doyou_want_sponsor`='$sponsorevent',`cat_id`='$select' where `id`='$id'");
				if($update){
					header("location:../myevent.php?status=success");
				}
				else {
					echo "<br/> line70: " . mysql_error();
					echo $id;
				}
				exit();
	}
	
	
	if(strlen($name ||$uploadfile)){
		$r=1;
	$update=$uprow['photo'];
	if($update){
		unlink("../../assets/img/eventphoto/" . $update);
		
	}
	if($updateag){
		
		unlink("../../assets/uploadfile/" . $updateag);
	}
	list($txt,$ext)=explode(".",$name);
		if (is_array($validformat)){
			if($size<(1024*1024)*6){
				$r=3;
				$atual_name=substr(str_replace(" ","_", $txt), 5).".".$ext;
			$temp=$_FILES['photo']['tmp_name'];
$insert=mysql_query("UPDATE `event` SET `title`='$title',`startdate`='$sdate',`enddate`='$edate',
`venue`='$venue',`description`='$description',`photo`='$atual_name',`agenda`='$agenda',
`speaker`='$speakar',`partner`='$partnar',`sponsor`='$sponsor',`organizer`='$organizer',
`doyou_want_exihabit`='$exihabitevent',`doyou_want_sponsor`='$sponsorevent',`cat_id`='$select' where `id`='$id'");
				if($insert){
					$movefile=move_uploaded_file($temp , $path.$atual_name);
					if(!$movefile){
						echo mysql_error();
						echo "FAILED";
						exit();
					}
					header("location:../myevent.php?status=suesses");
				}else{

					echo mysql_error()."not inserted dear please try agine";
				}

			}else{
				echo mysql_error()."name is not true";
			}
		}}
}else {
	echo "NO IMAGE";
}
?>